import java.awt.Color;
import java.util.ArrayList;


// this class maintains the list of all objects in the sketch being drawn currently
// this is a singleton class, only one sketch exists at a time.
public class PLSketch {

	private static PLSketch mSketch;

	// list of all shapes in the sketch being drawn
	ArrayList<PLShape> mShapes;
	ArrayList<Integer> mPlayerIds; // may be used to distinguish who drew what
	int mLast;

	private PLSketch() {
		mLast = 0;
		mShapes = new ArrayList<PLShape>();
		mPlayerIds = new ArrayList<Integer>();
		
	}

	public static synchronized PLSketch Obj() {
		if (mSketch == null) {
			mSketch = new PLSketch();
		}
		return mSketch;
	}

	// no cloning allowed
	public Object clone() throws CloneNotSupportedException {
		throw new CloneNotSupportedException();
	}

	public void clear() {
		mShapes.clear();
		mPlayerIds.clear();
		mLast = 0;
	}

	public boolean AddShape(PLShape shape,  int playerId) {
		mShapes.add(shape);
		mPlayerIds.add(new Integer(playerId));		
		return true;
	}

	public void BeginGet() { mLast = 0;}

	// returns the player id of the shape, 
	// returns -1 if shape is invalid
	public int GetNextShape(PLShape outShape) {
	
		if (mLast >= mShapes.size() )
			return -1;
		
		outShape = (PLShape) mShapes.get(mLast);

		return (int)mPlayerIds.get(mLast++);
	}

	public ArrayList<PLShape> GetAllShapes() {return mShapes;}

	public boolean DrawShape(PLShape shape, int playerId, Color color) {
		AddShape(shape, playerId);

		PLGuiInfo.Obj().GetCurCanvas().DrawShape(shape, color, false);

		return true;
	}
}

